<template>
	<view class="page">
		<image src="../../static/register/head.jpg" mode="widthFix" class="top" />
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">基本要求</text>
			</view>
			<view class="list">
				<view class="item">
					<text>1.</text>
					三年安全驾驶经验；
				</view>
				<view class="item">
					<text>2.</text>
					年龄23~55周岁；
				</view>
				<view class="item">
					<text>3.</text>
					无违法犯罪记录、无精神病史、无吸毒史，以及平台认为不适合代驾的其他历史证明；
				</view>
				<view class="item">
					<text>4.</text>
					有熟练驾车经验；
				</view>
				<view class="item">
					<text>5.</text>
					身体健康，无肢体残疾和大面积纹身；
				</view>
				<view class="item">
					<text>6.</text>
					需要提供身份证、驾驶证、直系亲属联系方式，并保存前述材料的真实合法性；
				</view>
			</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">加盟流程</text>
			</view>
			<view class="list">
				<view class="complex-item">
					<view class="left">01</view>
					<view class="right">
						<text class="item-title">在线注册</text>
						<text class="item-desc">在小程序上完成注册</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">02</view>
					<view class="right">
						<text class="item-title">基本信息提交</text>
						<text class="item-desc">按照流程提交本人身份证、驾驶证</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">03</view>
					<view class="right">
						<text class="item-title">信息审核</text>
						<text class="item-desc">对提交信息以及证件进行审核</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">04</view>
					<view class="right">
						<text class="item-title">签署合同</text>
						<text class="item-desc">收到邮寄的合同后必须本人签署</text>
					</view>
				</view>
			</view>
		</view>
		<button class="btn" open-type="getUserInfo" @tap="register()">立即加盟</button>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	export default {
		data() {
			return {

			};
		},
		methods: {
			async register() {
				try{
				//1获取用户昵称 头像等信息
				let userProfile = await uni.getUserProfile({
					desc: "获取用户信息"
				});
				//2获取临时code 
				const loginRes = await this.loginAsync();
				console.log("获取微信授权信息", loginRes);
				//3组装请求数据
				let data = {
					code: loginRes.code,
					nickname: userProfile.userInfo.nickName,
					photo: userProfile.userInfo.avatarUrl
				};
				console.log("组装请求数据", data);
				//4发起注册请求
				const result = await this.callAsync(this.urls.registerDriver, 'POST', data);
				console.log("注册返回数据", result);
				//5处理请求后的操作
				this.showSuccessMessage("司机注册成功!");
			}catch (err) {
                console.log("注册出现错误", err);
			}

		},
		loginAsync() {
			return new Promise((resolve, reject) => {
				uni.login({
					provider: 'weixin',
					success: (loginRes) => {
						resolve(loginRes);
					},
					fail: (error) => {
						reject(error);
					}
				});
			});
		},
		callAsync(url, method, data) {
			return new Promise((resolve, reject) => {
				this.request(url, method, data, resolve, reject);
			});
		},
		showSuccessMessage(message) {
			this.$refs.uToast.show({
				title: '成功',
				type: 'success',
				message,
				complete: () => {
					uni.setStorageSync('realAuth', 1);
					uni.redirectTo({
						url: "/pages/auth/auth"
					})
					console.log("注册成功！！");
				}
			});
		},
	}
	}
</script>

<style lang="less">
	@import url("register.less");
</style>